<?php

/**
 * ActiveRecord class
 *
 * @author Julot
 * @since Thursday, June 9, 2011. 06:15 PM
 */
class ActiveRecord extends CActiveRecord {

	/**
	 * If new record, set insertTime to current time.
	 * Else update updateTime to current time.
	 * @see CActiveRecord beforeSave.
	 */
	protected function beforeSave() {
		if (!parent::beforeSave()) return false;
		if ($this->isNewRecord) $this->insertTime = time();
		$this->updateTime = time();
		return true;
	}

	/**
	 * @return integer Epoch time
	 */
	public function getLastUpdate() {
		$criteria = new CDbCriteria;
		$criteria->order = 'updateTime DESC';
		$model = $this->model()->find($criteria);
		if ($model) return $model->updateTime;
		return time();
	}

}
